<?php


class MeetingAction extends SecurityAction{
	function _initialize(){
        $this->assign("menuFirst",session('menuFirst')); 
        $this->assign("menuSecond",session('menuSecond')); 
    }
		
	function mlist(){		
		$ob = M("yq_meeting");
		
		$sql = array();

		if ($_GET['shopname']){
			$sql['c.shopname'] = array('like',"%{$_GET['shopname']}%");
		}
		if($_GET['stime'] && $_GET['etime']){
		 	$stime = date('Y-m-d' ,$_GET['stime']);
		 	$etime = date('Y-m-d' ,$_GET['etime']);

			$sql['yq_meeting.add_time'] = array(array('EGT',$stime),array('ELT',$etime),'AND');
		}
		
		$year = "";
		$month = "";
		$shopid = $_GET["shopid"];
		
		if ($_GET["year"]){
			$year = $_GET["year"];
		}else{
			$year = date("Y", time());
		}
		if ($_GET["month"]){
			$month = $_GET["month"];
		}else{
			$month = date("m", time());
		}
		
		if($_GET['year'] || $_GET['month']){
			$sql[] = array('btime'=>array('like',"{$year}-{$month}%"));
		}
		
		if($shopid){
			$sql[] = array('yq_meeting.shopid'=>$shopid);
		}
		
		
		$cpp = 10; //分页数
        import('ORG.Util.Page');// 导入分页类
        $count      = $ob->join(" yq_member b on yq_meeting.memberid = b.tid")
        				 ->join(" yq_shop c on yq_meeting.shopid = c.tid ")
        				 ->field(" yq_meeting.title,yq_meeting.content,yq_meeting.btime,yq_meeting.etime,b.realname,c.shopname ")
        				 ->where($sql)->count();// 查询满足要求的总记录数
        $Page       = new Page($count,$cpp);// 实例化分页类 传入总记录数和每页显示的记录数
        $show       = $Page->show();// 分页显示输出
        
		$list = $ob->join(" yq_member b on yq_meeting.memberid = b.tid")
				   ->join(" yq_shop c on yq_meeting.shopid = c.tid ")
				   ->field(" yq_meeting.tid,yq_meeting.title,yq_meeting.content,yq_meeting.btime,yq_meeting.etime,b.realname,c.shopname ")
				   ->where($sql)
				   ->limit($Page->firstRow.','.$Page->listRows)->select();

		$this->assign("list", $list);
		$this->assign('show',$show);// 赋值分页输出

		$shopOb = M("yq_shop");
		$shoplist = $shopOb->select();
		$this->assign("shoplist", $shoplist);
		
		$this->display("Meeting/mlist");
	}
	
	function detail(){
		$ob = M("yq_meeting");

		$sql[] = array('yq_meeting.tid'=>$_GET['tid']);
		$info = $ob->join(" yq_member b on yq_meeting.memberid = b.tid")
				   ->join(" yq_shop c on yq_meeting.shopid = c.tid ")
				   ->field(" b.realname,c.shopname,yq_meeting.* ")
				   ->where($sql)->find();
		$info['rcontents'] = json_decode($info['rcontents'],true);
		$info['hcontents'] = json_decode($info['hcontents'],true);
/*		$rval = '';  //美容任务分配
		$hval = '';  //任务没法分配
		foreach ($info['rcontents'] as $key => $value) {
			$rval = $rval. $value .';';
		}
		foreach ($info['hcontents'] as $key => $value) {
			$hval = $hval. $value .';';
		}
		$info['rcontents'] = $rval;
		$info['hcontents'] = $hval;*/

		$this->assign("info", $info);
		$this->display("Meeting/detail");
	}
}

?>